<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>截取字符</title>
</head>
<body>
    
</body>
</html>
<script>
    //下例子对数组进行代理，用于截取标题操作
    const lesson = [
        {
            title : "媒体查询响应式布局",
            category : "css"
        },
        {
            title : "FLEX弹性盒子模型",
            category : "css"
        },
        {
            title : "MYSQL多表查询随意操作",
            category : "mysql"
        }
    ];

    const stringDotProxy = new Proxy(lesson,{
        get(target,key=null){
            if(key != null){
                return target[key];
            }else{
                return target;
            }
        },
        set(target,key,len){
            const title = target[key].title;
            target[key].title = title.length > len ? title.substr(0,len)+'.'.repeat(3) : title;
        }
        
    });

    //读取的时候已经调用代理中的get方法
    for(let i = 0 ; i < lesson.length;i++){
        stringDotProxy[i] = 5;
    }
   console.log(lesson);

</script>